﻿using System;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Schema;

namespace AOUtils.Libraries
{
    public class AttackValue : IXmlSerializable
    {
        [XmlAttribute]
        public AttackValueTypes Name
        {
            get;
            set;
        }
        [XmlAttribute]
        public int Percent
        {
            get;
            set;
        }

        #region IXmlSerializable Members

        public XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            reader.MoveToAttribute(0);
            switch (reader.Value)
            {
                case "1hBlunt":
                    Name = AttackValueTypes.OneHandBlunt;
                    break;
                case "2hBlunt":
                    Name = AttackValueTypes.TwoHandBlunt;
                    break;
                case "1hEdged":
                    Name = AttackValueTypes.OneHandEdged;
                    break;
                case "2hEdged":
                    Name = AttackValueTypes.TwoHandEdged;
                    break;
                case "MG/SMG":
                    Name = AttackValueTypes.MG_SMG;
                    break;
                default:
                    Name = (AttackValueTypes)Enum.Parse(typeof(AttackValueTypes), reader.Value);
                    break;
            }
            reader.MoveToAttribute("Percent");
            Percent = int.Parse(reader.Value);
            reader.Read();
        }

        public void WriteXml(XmlWriter writer)
        {
            writer.WriteAttributeString("Name", Name.ToString());
            writer.WriteAttributeString("Percent", Percent.ToString());
        }

        #endregion
    }
}
